//
//  LGInspectionAnomalyCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/2.
//  异常指标Cell

#import "LGInspectionAnomalyCell.h"

@interface LGInspectionAnomalyCell()
/**   */
@property (nonatomic , strong)UIView *shadowView;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIButton *deleteBtn;
/**   */
@property (nonatomic , strong)UIButton *editButton;
/**   */
@property (nonatomic , strong)UILabel *valueLabel;
/**   */
@property (nonatomic , strong)UILabel *referenceLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;

@end

@implementation LGInspectionAnomalyCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setIndex:(NSInteger)index{
    _index = index;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = LGNSString(dataDic[@"entry_name"]);
    self.valueLabel.text = [NSString stringWithFormat:@"%@   %@   %@",dataDic[@"result"],dataDic[@"unit"],dataDic[@"arrow"]];
    self.referenceLabel.text = [NSString stringWithFormat:@"参考值：%@",dataDic[@"range"]];
}

//删除
-(void)deleteBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(deleteAnomalyNorm:)]){
        [self.delegate deleteAnomalyNorm:self.index];
    }
}

//编辑
-(void)editBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(editAnomalyNorm:)]){
        [self.delegate editAnomalyNorm:self.index];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.shadowView];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.deleteBtn];
    [self.baseView addSubview:self.editButton];
    [self.baseView addSubview:self.valueLabel];
    [self.baseView addSubview:self.referenceLabel];
    [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(10));
        make.right.equalTo(self.deleteBtn.mas_left).offset(-viewPix(10));
    }];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(8));
        make.right.equalTo(self.editButton.mas_left).offset(-viewPix(8));
        make.width.equalTo(@(viewPix(60)));
        make.height.equalTo(@(viewPix(24)));
    }];
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(8));
        make.top.width.height.equalTo(self.deleteBtn);
    }];
    [self.valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.editButton);
    }];
    [self.referenceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.valueLabel.mas_bottom).offset(viewPix(8));
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
        make.left.right.equalTo(self.valueLabel);
    }];
}
-(UIView *)shadowView{
    if(!_shadowView){
        _shadowView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _shadowView.backgroundColor = [UIColor whiteColor];
    }
    return _shadowView;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#EFEFEF"];
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _titleLabel;
}

-(UIButton *)deleteBtn{
    if(!_deleteBtn){
        _deleteBtn = [UIButton buttonWithTitle:@"删除" titleFont:LGFont(14) textColor:@"#DD3030" imageName:@""];
        _deleteBtn.layer.borderColor = [UIColor colorWithString:@"#DD3030"].CGColor;
        _deleteBtn.layer.borderWidth = 1;
        _deleteBtn.cornerRidus = viewPix(12);
        [_deleteBtn addTarget:self action:@selector(deleteBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteBtn;
}

-(UIButton *)editButton{
    if(!_editButton){
        _editButton = [UIButton buttonWithTitle:@"编辑" titleFont:LGFont(14) textColor:@"#3291FF" imageName:@""];
        _editButton.layer.borderColor = [UIColor colorWithString:@"#3291FF"].CGColor;
        _editButton.layer.borderWidth = 1;
        _editButton.cornerRidus = viewPix(12);
        [_editButton addTarget:self action:@selector(editBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editButton;
}


-(UILabel *)valueLabel{
    if(!_valueLabel){
        _valueLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _valueLabel;
}


-(UILabel *)referenceLabel{
    if(!_referenceLabel){
        _referenceLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _referenceLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
